include_javaScript(url_prefix+'editor/ckeditor/ckeditor.js');
include_javaScript(url_prefix+'editor/ckfinder/ckfinder.js');


$(function() { 
    $("#tabs").tabs();
    $( "#ToDate,#FromDate" ).datepicker({
        dateFormat: "dd-mm-yy"
    });
});
 
$(document).ready(function() { 
    hs.graphicsDir = url_base+'app/admin/view/temp/default/layout/css/highslide/graphics/';
    hs.align = 'center';
    hs.closeText = '<img border="0" src="'+url_base+'app/admin/view/temp/default/layout/css/highslide/graphics/close_X.png" />';
    hs.creditsText = 'this.a.title';
    hs.outlineType = 'rounded-white';
    hs.showCredits = false;
    hs.wrapperClassName = 'draggable-header';
    hs.cacheAjax = false;
    hs.dimmingOpacity = 0.7;
    hs.onDimmerClick = function() {
        return false;
    }
    
     
    $('#btn-submit').click(function() {  
    
        var hasError = false;
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    
        var emailaddressVal = $("#Email").val();
        if(emailaddressVal == '') {
            $(".error").show().text(_['error-emal-empty']);
            hasError = true;
        }
    
        else if(!emailReg.test(emailaddressVal)) {
            $(".error").show().text(_['error-emal-no-format']);
            hasError = true;
        }
    
        if(hasError == true) {
            return false;
        }
    
    });
    
    $('input:checkbox[name="delId[]"]').click(function() { 
    
        if( $(this).attr("checked")== "checked"){
        
            $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);
        
        }else{
        
            if(getValCb().length>0)
            {               
                $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);
            }else{
                $('.but_tool').removeClass('but_login').addClass('butx').attr("disabled",true);   
            }
        
        
        }
    
    });
	
    $('#Percent').blur(function(){
        $Percent = $(this).val();
        if(isNaN($Percent)){
			
            alert(_['check_percent_is_text']);
		
        }
        else if(0>$Percent || $Percent>100){
		
            alert(_['check_percent_0_100']);
            if(0>$Percent){
                $(this).val(0);
            }else{
                $(this).val(100);
            }
			
        }else{
			
			
        }
		
    });
	
});
 
function checkAll()
{
    if(getValCb().length>0){
        
        $('.but_tool').removeClass('but_login').addClass('butx').attr("disabled",true);
        
        $('input:checkbox[name="all"]').removeAttr("checked");
        $('input:checkbox[name="delId[]"]').removeAttr("checked");
        
    }else{
	    
        $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);
        
        $('input:checkbox[name="all"]').attr("checked","checked");
        $('input:checkbox[name="delId[]"]').attr("checked","checked");
    }
	
}

function getValCb()
{
    var delId = [];
    $('input:checkbox[name="delId[]"]:checked')
    .each( function(index) { 
        delId.push($(this).val());
    });
	
    return delId;
}

function del_pic(path_pic,CatID)
{
    var url = _seokey[0]+"/"+_seokey[1]+"/ajax/delpic/"+CatID+"/"+path_pic+"/";
    $.ajax({
        type    : "GET",
        url     : url_base+url,
        cache   : false,
        dataType: "html",
        success: function(DataHtml)
        {
            document.getElementById('id_img').src=url_base+'upload/noimg.png';
            $('#id_img_but').hide();
            $('#id_img_input').show();
        }

    });

}

function processChecked(active)
{
    var StrID = getValCb();
    switch (active)
    {
        case 'show':
            var strData = _seokey[0]+"/"+_seokey[1]+"/ajax/"+active+"/"+StrID;
            var sms = _['showx'];
            var smsError=_['error_show'];
            var errorNotOK = _['error_ok_show'];
            var status = _['show'];
            var activea = 'hide';
            var activeb = 'del';
            break;
		
        case 'hide':
            var strData = _seokey[0]+"/"+_seokey[1]+"/ajax/"+active+"/"+StrID;
            var sms = _['hidex'];
            var smsError=_['error_hide'];
            var errorNotOK = _['error_ok_hide'];
            var status = _['hide'];
            var activea = 'show';
            var activeb = 'del';
            break;
		
        case 'del':
            var strData = _seokey[0]+"/"+_seokey[1]+"/ajax/"+active+"/"+StrID;
            var sms = _['delx'];
            var smsError=_['error_del'];
            var errorNotOK = _['error_ok_del'];
            var status = _['del'];
            var activea = 'hide';
            var activeb = 'show';
            break;
        
        case 'delete':
            var strData = _seokey[0]+"/"+_seokey[1]+"/ajax/"+active+"/"+StrID;
            var sms = _['delete'];
            var smsError=_['error_delete'];
            var errorNotOK = _['error_ok_delete'];
            var deletex = 'ok';
            break;
        
    }
	
    if(StrID!=""){
        var smsCheck = confirm(sms);
        if(smsCheck==true){
            $.ajax({ 
                type: "POST", 
                url: url_base+""+strData, 
                cache: false,
                dataType: "html",
                success: function(DataHtml){ 
                    if(DataHtml=='ok')
                    {
                        for(x in StrID)
                        {
                            if(deletex)
                            {
                                $('.tr'+StrID[x]).remove();                                
                            }
                            else{
                         
                                $('.status'+StrID[x]).text(status);
                            
                                if($('.tr'+StrID[x]).hasClass('class_'+activea) )
                                    $('.tr'+StrID[x]).removeClass('class_'+activea);
                                if($('.tr'+StrID[x]).hasClass('class_'+activeb) )
                                    $('.tr'+StrID[x]).removeClass('class_'+activeb);
                            
                                $('.tr'+StrID[x]).addClass('class_'+active);
                            
                            
                            }
                        
                        }
                    }
                    else{
                        alert(errorNotOK);                   
                    
                    }
				 
                } 
            });
        }
	
    }else{
        alert(smsError);
	
    }
}

function create_seo(lang)
{ 
    var $name = $('#Name_'+lang).val();
    var FullContents = 'FullContents_'+lang;
    var $seokey = getLinkSeo($name);
   
    $('#SeoKey_'+lang).val($seokey);
    $('#Title_'+lang).val($name);
   
    $('#Keyword_'+lang).val($name);
    $('#TitleH1_'+lang).val($name);
   
   
    var Desc = 'Desc_'+lang;
    var DescF = 'DescF_'+lang;
    var TitleH2 = 'TitleH2_'+lang;
    $('#TitleH2_'+lang).val($name);
    $('#Desc_'+lang).val($name);
    CKEDITOR.instances[DescF].setData($name);

/*var $des = CKEDITOR.instances[FullContents].getData();
   CKEDITOR.instances[TitleH2].setData($name);
   CKEDITOR.instances[Desc].setData($name);
    */

}

function Search(flag ,cur)
{   
    var key = $("#search").val();
    var cat = $("#submenus").val();
    if(key == '')
        key = 'all';
    
    var url = _seokey[0]+"/"+_seokey[1]+"/ajax/search/"+key+"/"+cat+'/'+cur;
    if(flag == 'press')
    {
        if(event.keyCode == 13)
        {           
            $.ajax({
                type    : "GET",
                url     : url_base+url,
                cache   : false,
                dataType: "html",
                success: function(DataHtml)
                {            
                    $('#search_res').html(DataHtml);
                    $("#search").focus();
                }

            });
        }
    }
    else if(flag == 'click')
    {        
        $.ajax({
            type    : "GET",
            url     : url_base+url,
            cache   : false,
            dataType: "html",
            success: function(DataHtml)
            {   
                $('#search_res').html(DataHtml);
                $("#search").focus();
            }

        });
    }
    
}


